package com.ruoyi.apduParse.strategy;

import com.ruoyi.apduParse.dto.AidInfo;
import com.ruoyi.apduParse.dto.SentenceFactoryDto;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class SelectSentenceStrategy implements SentenceStrategy {

    @Override
    public String getSentenceOfapduName(SentenceFactoryDto factoryDto) {
        String sentence = "选取{}";
        return getApduRealUse(sentence,factoryDto.getAidInfos());
    }

    /**
     * 拼接
     * @param sentence
     * @param aidInfos
     * @return
     */
    private String getApduRealUse(String sentence, List<AidInfo> aidInfos) {
        log.info("拼接语句：{}",sentence);

        for (AidInfo aidInfo : aidInfos) {
            String aidName = aidInfo.getAidName();
            log.info("aidName:{}", aidName);
            sentence = StringUtils.format(sentence, aidName);
        }
        log.info("已经拼接好的语句：{}",sentence);

        return sentence;
    }
}
